package com.sky.controller.admin;

import com.sky.dto.LongController;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单管理
 */
@RestController
@RequestMapping("/admin/order")
@Api(tags = "订单相关接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 查询订单详情
     */
    @GetMapping("/details/{id}")
    public Result<OrderDetailVO> selectOrderDetail(@PathVariable Integer id) {
        OrderDetailVO vo=ordersService.selectOrderDetail(id);
        return Result.success(vo);
    }
    /**
     * 接单
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody LongController longController){
        ordersService.confirm(longController);
        return Result.success();

    }

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult result = ordersService.conditionSearch(ordersPageQueryDTO);
        return Result.success(result);
    }

    /**
     * 修改订单为派送状态
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("修改订单为派送状态")
    public Result delivery(@PathVariable("id") Long id){
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 修改订单为完成状态
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("修改订单为完成状态")
    public Result complete(@PathVariable("id") Long id){
        ordersService.complete(id);
        return Result.success();
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        return Result.success(ordersService.statistics());
    }
}
